#ifndef HISTORYMESSAGEWIDGET_H
#define HISTORYMESSAGEWIDGET_H

#include <QDialog>
#include <QWidget>
#include <QLabel>

#include "model/data.h"

namespace model {
    class Message;
}

class QRadioButton;
class QLineEdit;
class QGridLayout;
class QDateTimeEdit;


class HistoryMessageWidget : public QDialog
{
    Q_OBJECT
public:
    HistoryMessageWidget(QWidget* parent);

    void addHistoryMessage(const model::Message& message);

    void clear();

private:
    void initScrollArea(QGridLayout* layout);

    void onClickedBySearchBtn();

    void searchMessageDoneHandle();

private:
    QWidget* container;     // 历史消息存储区

    QLineEdit* searchEdit;

    QRadioButton* keyRadioBtn;
    QRadioButton* timeRadioBtn;

    QDateTimeEdit* beginTimeEdit;
    QDateTimeEdit* endTimeEdit;
};


///////////// 历史消息控件类
class HistoryMessageItem : public QWidget
{
    Q_OBJECT
public:
    HistoryMessageItem();

    static HistoryMessageItem* makeHistoryMessageItem(const model::Message& message);
};


///////////// 图片类型历史消息
class ImageMessageItem : public QPushButton
{
    Q_OBJECT
public:
    ImageMessageItem(const QString& fileId, const QByteArray& content);

private:
    void getSingleFileDoneHandle(const QString& fileId, const QByteArray& content);
    void loadImage(const QByteArray& imageData);
    void updateImageSize();
private:
    QString fileId;
    QImage image;
    QSize imageSize;
    bool imageLoaded;
};


///////////// 文件类型历史消息
class FileMessageItem : public QLabel
{
    Q_OBJECT
public:
    FileMessageItem(const QString& fileId, const QByteArray& content, const QString& fileName);

protected:
    void mousePressEvent(QMouseEvent* event);

private:
    void getSingleFileDoneHandle(const QString& fileId, const QByteArray& content);

private:
    QString fileId;
    QByteArray content;
    QString fileName;
    bool loadDone;
};

///////////// 语音类型历史消息
class SpeechMessageItem : public QLabel
{
    Q_OBJECT
public:
    SpeechMessageItem(const QString& fileId, const QByteArray& content);

protected:
    void mousePressEvent(QMouseEvent* event);

private:
    void getSingleFileDoneHandle(const QString& fileId, const QByteArray& content);

private:
    QString fileId;
    QByteArray content;
    QString fileName;
    bool loadDone;
};


#endif // HISTORYMESSAGEWIDG ET_H
